package com.prj.ufdm.cloud.ms.auth.bpo._impl;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.prj.ufdm.cloud.base.util.BaseUuidUtil;
import com.prj.ufdm.cloud.ms.auth.bpo.SysUserRoleBPO;
import com.prj.ufdm.cloud.ms.auth.dao.SysUserRoleDao;
import com.prj.ufdm.cloud.ms.auth.model.SysUserRole;
import com.prj.ufdm.cloud.ms.core.bpo._impl.BaseBPOImpl;

/**
 * DESC: 用户角色BPO <br>
 * @author 胡义振
 * @date 2020年1月17日
 */
@Service 
public class SysUserRoleBPOImpl extends BaseBPOImpl<SysUserRoleDao,SysUserRole> implements SysUserRoleBPO {
	
	@Autowired
	SysUserRoleDao sysUserRoleDao;
	
	/**
	 * Desc: 在用户中添加角色
	 * @param 
	 *      userId      用户ID
	 *      roleIds     角色ID（多个用","号分隔）
	 * @return
	 * @author 胡义振  
	 * @date 2018年3月26日
	 */
	public Integer doAddSysUserRole(String userId,String roleIds) throws Exception {
		if (roleIds == null)  roleIds = "";
		sysUserRoleDao.deleteUserRoleByUserId(userId);
		String[] arrRoleId = roleIds.split(",");
		for(String roleId : arrRoleId){
			SysUserRole sysUserRole = new SysUserRole();
			sysUserRole.setId(BaseUuidUtil.getUUID());
			sysUserRole.setRoleId(roleId);
			sysUserRole.setUserId(userId);
			sysUserRoleDao.insertOne(sysUserRole);
		}
		return arrRoleId.length;
	}

}
